package com.app.configs;

import com.app.runtime.RESTUtils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Hendra on 12/27/2014.
 */
public class Repository extends ResConfig implements RESTUtils {

    private static final Logger logger = LoggerFactory.getLogger(Repository.class);

    protected URL url;
    protected HttpURLConnection connection;
    protected BufferedReader br;
    protected OutputStream os;

    protected String uri;

    protected final boolean connect = false;

    public String getMessages() {
        return messages;
    }

    public void setMessages(String messages) {
        this.messages = messages;
    }

    private String messages;
    private String Path;

    public String getPath() {
        return Path;
    }

    public void setPath(String path) {
        Path = path;
    }

    public Repository(String path){
        super();
        this.Path = path;
        uri = String.format("http://%s:%s/%s", getCti_url(), getCti_port(), getPath());
    }

    public void openConnection(){
//        try{
//            logger.info("Try Connect server: " + uri);
//            if(!connect){
//                url = new URL(uri);
//                connection = (HttpURLConnection) url.openConnection();
//                connection.setRequestMethod("GET");
//                connection.setRequestProperty("Accept", "application/json");
//                if (connection.getResponseCode() != 200) {
//                    logger.error("Failed : HTTP error code : "
//                            + connection.getResponseCode());
//                }
//                BufferedReader br = new BufferedReader(new InputStreamReader(
//                        (connection.getInputStream())));
//                logger.info("Connected: " + br);
//
//                connection.disconnect();
//            }
//        }catch (Exception e){
//            logger.error("error: ", e);
//            e.printStackTrace();
//        }
    }

    public void post(String params){
        logger.info("POST " +getMessages());
    }
    public void put(String params){
        logger.info("PUT " + getMessages());
    }
    public void delete(String params){
        logger.info("DELETE " +getMessages());
    }
    public void get(String params){
        logger.info("GET " +getMessages());
    }
}
